varying vec3 lightDir; 
varying vec3 eyeDir;
varying vec3 reflectDir;
varying vec3 refractDir;
varying float FresRatio;
uniform sampler2D normalMap;
uniform samplerCube cubeMap;


void main (void)
{

   float distSqr = dot(lightDir, lightDir);
   float att = clamp(1.0 - 0.0 * sqrt(distSqr), 0.0, 1.0);
   vec3 lVec = lightDir * inversesqrt(distSqr);

   vec3 vVec = normalize(eyeDir);

   vec4 base = vec4(0.17,0.67,0.93,1.0); //base water color
   
   vec3 bump = normalize( texture2D(normalMap, gl_TexCoord[1]).xyz * 2.0 - 1.0);
   vec3 secbump = normalize( texture2D(normalMap, gl_TexCoord[2]).xyz * 2.0 - 1.0);
   vec3 modbump = mix(secbump,bump,0.5);
  
   vec3 reflection = vec3(textureCube(cubeMap,reflect(eyeDir,modbump)));
   vec3 refraction = vec3(textureCube(cubeMap,refract(eyeDir,modbump,0.66)));
   vec3 cubemap = mix(reflection,refraction,FresRatio);


   vec4 vAmbient = gl_LightSource[0].ambient;

  float diffuse = max( dot(-lVec, modbump), 0.0 );
   
   vec4 vDiffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * diffuse;   
   float specular = pow(clamp(dot(reflect(lVec, modbump), vVec), 0.0, 1.0), 0.5 );
   
   vec4 vSpecular = gl_LightSource[0].specular * gl_FrontMaterial.specular * specular;   
   
   vec4 newfrag = mix(vec4(cubemap,1.0) , (( vAmbient*base + vDiffuse*base * vSpecular*base ) * att),0.1);
   
   gl_FragColor = newfrag; //mix(vec4(cubemap,1.0),base,0.5) ; //newfrag;
}